#pragma once
#include"hashtable.h"

namespace my_umap
{
	template<class K, class V,class Hash = HashFunc<K>>
	class unordered_map
	{
	public:
		struct MapOfT
		{
			const K operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};

		typedef typename hash_bucket::HashTable<K, pair<const K, V>,
			MapOfT, Hash>::Iterator iterator;
		typedef typename hash_bucket::HashTable<K, pair<const K, V>,
			MapOfT, Hash>::ConstIterator const_iterator;

		pair<iterator,bool> insert(const pair<K, V>& kv)
		{
			return _ht.Insert(kv);
		}

		V& operator[](const K& k)
		{
			pair<iterator, bool> ret = insert(make_pair(k, V()));
			return ret.first->second;
		}

		iterator begin()
		{
			return _ht.Begin();
		}

		iterator end()
		{
			return _ht.End();
		}

		const_iterator begin() const
		{
			return _ht.Begin();
		}

		const_iterator end() const
		{
			return _ht.End();
		}
	private:
		hash_bucket::HashTable<K, pair<const K, V>, MapOfT, Hash> _ht;
	};

}